package com.xiaoniu.forum.web.controller;

import java.util.Arrays;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.xiaoniu.forum.entity.BannerEntity;
import com.xiaoniu.forum.service.BannerService;
import com.xiaoniu.forum.common.utils.PageUtils;
import com.xiaoniu.forum.common.utils.R;



/**
 * 轮播图
 *
 * @author xiaoniu
 * @email 55333@qq.com
 * @date 2021-03-17 10:26:48
 */
@RestController
@RequestMapping("forum/banner")
@Api("Banner管理")
public class BannerController {
    @Autowired
    private BannerService bannerService;

    /**
     * 列表
     */
    @GetMapping("/list")
    @ApiOperation("查看列表")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = bannerService.queryPage(params);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @ApiOperation("根据ID查看")
    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") String id){
		BannerEntity banner = bannerService.getById(id);
        return R.ok().put("banner", banner);
    }

    /**
     * 保存
     */
    @ApiOperation("保存数据")
    @PostMapping("/save")
    public R save(@RequestBody BannerEntity banner){
        bannerService.addBanner(banner);
        return R.ok();
    }

    /**
     * 修改
     */
    @ApiOperation("修改数据")
    @PostMapping("/update")
    public R update(@RequestBody BannerEntity banner){
		bannerService.updateBannerById(banner);
        return R.ok();
    }

    /**
     * 删除
     */
    @ApiOperation("批量删除")
    @PostMapping("/delete")
    public R delete(@RequestBody String[] ids){
        bannerService.removeBannerByIds(Arrays.asList(ids));
        return R.ok();
    }

}
